<!-- <template>
	<view class="page">
		<view class="user-info">
			<view class="summary">
				<view>
					<text class="title">用户名称</text>
					<text class="value">{{realName}}</text>
				</view>
			</view>
		</view>
		<uni-list>
			<uni-list-item title="我的考勤" link to="/pages/my_checkin/my_checkin"></uni-list-item>
		</uni-list>	
	</view>
</template> -->
<template>
	<view class="page">
		<!-- 个人信息部分 start -->
		<view class="user-info">
			<view class="summary">
				<view>
					<text class="title">用户名称</text>
					<text class="value">{{realName}}</text>
				</view>
			</view>
			<view class="summary">
				<view>
					<text class="title">公司名称</text>
					<text class="value">{{user.company}}</text>
				</view>
			</view>
			<view class="summary">
				<view>
					<text class="title">部门</text>
					<text class="value">{{department.departmentName}}</text>
				</view>
			</view>
			<view class="summary" v-if="ifWR">
				<view>
					<text class="title">工区</text>
					<text class="value">{{workRegion.regionName}}</text>
				</view>
			</view>	
			<view class="modify-button" @click="goToModifyPage">
				<text>修改信息</text>
			</view>
		</view>
		<uni-list>
			<uni-list-item title="我的考勤" link to="/pages/my_checkin/my_checkin"></uni-list-item>
		</uni-list>	
	</view>
</template>


<script>
	import uniList from '@/components/uni-list/uni-list.vue';
	import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
	import utils from '@/utils/utils.js';
	export default {
		components:{
			uniList,
			uniListItem
		},
		data() {
			return {
				userId:"",
				realName:"",
				photo:"",
				
				user:"",
				
				department:'',
				workRegion:'',
				ifWR:false
			}
		},
		onLoad:function(){
			let user1 = this.checkLogin()
			let that = this
			// 查询用户的概要信息
			that.ajax(that.url.searchUserSummary,"GET",null,function(resp){
				let result =resp.data.data
				that.userId=result.userId
				that.realName=result.realName
				that.user = result
				utils.logging('用户的概要信息为：',result)
				
					// 部门信息
				that.ajax(that.url.findDepartmentById+"/"+result.department,"GET",null,function(resp){
					let result =resp.data.data
					utils.logging('用户的概要信息为：',result)
					that.department = result
				})
				// 工区信息
				if(result.workRegion != null && result.workRegion != 0){
					that.ajax(that.url.findRegioWorkById+"/"+result.workRegion,"GET",null,function(resp){
						let result =resp.data.data
						utils.logging('用户的概要信息为：',result)
						that.workRegion = result
						that.ifWR = true
					})
				}
			})
			
		},
		onShow:function(){
			this.ifWR = false
			// console.log("123")
			let that=this
			// 查询用户的概要信息
			that.ajax(that.url.searchUserSummary,"GET",null,function(resp){
				let result =resp.data.data
				that.userId=result.userId
				that.realName=result.realName
				that.user = result
				utils.logging('用户的概要信息为：',result)
				that.ajax(that.url.findDepartmentById+"/"+result.department,"GET",null,function(resp){
					let result =resp.data.data
					utils.logging('用户的概要信息为：',result)
					that.department = result
				})
				
				// 工区信息
				if(result.workRegion != null && result.workRegion != 0){
					that.ajax(that.url.findRegioWorkById+"/"+result.workRegion,"GET",null,function(resp){
						let result =resp.data.data
						utils.logging('用户的概要信息为：',result)
						that.workRegion = result
						that.ifWR = true
					})
				}
			})
			
			},

		methods: {
			// 检查权限判断是否显示对应的菜单
			checkPermission:function(need_permission){
				var user_permission = uni.getStorageSync("permission")
				return utils.checkPermission(user_permission,need_permission)
			},
			
			// 修改
			goToModifyPage() {
				uni.navigateTo({
					url: '/pages/mine/updataMy/updataMy?info=' + encodeURIComponent(JSON.stringify(this.user)),
					success() {
						let page = getCurrentPages();
						console.log(page.length)
						page[page.length - 2].onLoad(); 
					}
				});
			}
			
		}
	}
</script>

<style lang="less">
	@import url("mine.less");
</style>
